package entity;

import java.util.List;

/**
 * Values and methods for specifying the CLASS property
 * for the iCalendar object as defined in RFFC 5545. 
 * This property defines the access classification for a 
 * calendar component.
 * 
 * @author Sean Young
 * @version 1.0
 *
 */
public class Classification implements EntityConstants{
	
	 /** A string containing the parameters for the CLASS property */
	private String classparam;
	
	/** The value of the PRIORITY property */
	private String classvalue;
	
	/**
     * Constructor for the CLASS property. Fields are defaulted
     * to null and the value is defaulted to PUBLIC (1).
     */
	public Classification() {
		classparam = null;
		classvalue = "PUBLIC";
	}
	
	/**
     * Constructor for the CLASS property. Sets the value of the 
     * CLASS property to the value specified in the parameter.
     * @param classification The classification level. 
     *                       1 = PUBLIC, 2 = PRIVATE, 3 = CONFIDENTIAL.
     *                       As defined in EntityConstants.java.
     */
	public Classification(int classification) {
		classparam = null;
		classvalue = "PUBLIC";
		this.setClassValue(classification);
	}
	
	/**
     * Sets the parameters for the CLASS property. Must be a single parameter.
     * @param classparam The parameter to be added to the CLASS property.
     *                   The parameter must be a single parameter.
     */
	public void setClassParam(String classparam) {
		this.classparam = classparam;
	}
	
	/**
     * Sets the value of the parameter for the CLASS property.
     * @param classparams A list of parameters to be added to the CLASS
     *                    property. 
     */
	public void setClassParam(List<String> classparams) {
		StringBuilder parameterBuilder = new StringBuilder(" ");
		for(int i = 0; i < classparams.size(); i++) {
			parameterBuilder.append(classparams.get(i));
			if((classparams.size() != 1) && (i != classparams.size() - 1)) parameterBuilder.append(";");
		}
		this.classparam = parameterBuilder.toString();
	}
	
	/**
     * Sets the value of the CLASS property.
     * @param priority The classification level. 
     *                 1 = PUBLIC, 2 = PRIVATE, 3 = CONFIDENTIAL.
     *                 As defined in EntityConstants.java.
     */
	public void setClassValue(int value) {
		switch (value) {
			case PUBLIC:       this.classvalue = "PUBLIC"; break;
			case PRIVATE:      this.classvalue = "PRIVATE"; break;
			case CONFIDENTIAL: this.classvalue = "CONFIDENTIAL"; break;
			default:           this.classvalue = "PUBLIC"; break;
		}
	}
	
	/**
	 * Returns a string containing the values of the fields of the
	 * DTST property. If no parameters were specified then they 
	 * will not be included. If no start date was specified then a null
	 * will be returned.
	 * 
	 * @return A string containing the properly formatted CLASS property.
	 */
	public String toString() {
		StringBuilder classString = new StringBuilder("CLASS");
		
		if(classparam != null) classString.append(classparam);
		
		classString.append(":");		
		
		classString.append(classvalue);
		classString.append("\r\n");
		
		return classString.toString();
	}
	

}
